//
//  LGTHomeHeaderView.swift
//  KJLGT
//
//  Created by jenkin on 2019/9/3.
//  Copyright © 2019年 jenkin. All rights reserved.
//

import UIKit

class LGTHomeHeaderView: UITableViewHeaderFooterView {

    var adView:UIImageView?
    
    //simple highprice invitation myreceipt
    // 简单任务  高价任务 邀请好友  我的接单
    // 新福利 赚不停 享特权 更快捷
    
    override init(reuseIdentifier: String?) {
        super.init(reuseIdentifier: reuseIdentifier)
        self.backgroundColor = UIColor.white
        self.contentView.backgroundColor = UIColor.white
        let data:Array<Dictionary<String, Any>> = [
                ["title":"简单任务", "desc":"新福利", "icon":"simple"],
                ["title":"高价任务", "desc":"赚不停", "icon":"highprice"],
                ["title":"邀请好友", "desc":"享特权", "icon":"invitation"],
                ["title":"我的接单", "desc":"更快捷", "icon":"myreceipt"]
            ]
        let count:Int = data.count
        let x0:CGFloat = SizeFitFloat(9)
        let w:CGFloat = SizeFitFloat(81)
        let h:CGFloat = SizeFitFloat(61)
        let spaceX:CGFloat = (KScreenW - 2 * x0 - w * CGFloat(count)) / CGFloat(count)
        for i in 0..<count{
            
            let info:Dictionary<String, Any> = data[i]
            let title:String = info["title"] as! String
            let desc:String = info["desc"] as! String
            let icon:String = info["icon"] as! String
            
            let button = LGTViewCreateUtil.share.createButton(image: icon, selected: icon)
            self.addSubview(button)
            button.snp.makeConstraints { (make) in
                make.left.equalTo(x0 + CGFloat(i) * (w + spaceX))
                make.top.equalTo(SizeFitFloat(145))
                make.width.equalTo(w)
                make.height.equalTo(h)
            }
            
            let titleLabel = LGTViewCreateUtil.share.createLabel(textAlignment: NSTextAlignment.left, textColor: TextColor, fontSize: 0, text: title)
            titleLabel.font = Font_Bold_13
            button.addSubview(titleLabel)
            titleLabel.snp.makeConstraints { (make) in
                make.left.equalTo(SizeFitFloat(7))
                make.top.equalTo(SizeFitFloat(7))
                make.height.equalTo(SizeFitFloat(14))
            }
            
            let descLabel = LGTViewCreateUtil.share.createLabel(textAlignment: NSTextAlignment.left, textColor: GrayColor, fontSize: SizeFitFloat(11), text: desc)
            button.addSubview(descLabel)
            descLabel.snp.makeConstraints { (make) in
                make.left.equalTo(SizeFitFloat(7))
                make.top.equalTo(SizeFitFloat(27))
                make.height.equalTo(SizeFitFloat(14))
            }
            
            if i == 0{
                descLabel.textColor = ColorUtil(color: 0xF2421F)
            }
        }
        
        let recommendLabel = LGTViewCreateUtil.share.createLabel(textAlignment: NSTextAlignment.left, textColor: TextColor, fontSize: 0, text: "推荐任务")
        recommendLabel.font = Font_Bold_18
        self.addSubview(recommendLabel)
        recommendLabel.snp.makeConstraints { (make) in
            make.top.equalTo(SizeFitFloat(229))
            make.left.equalTo(SizeFitFloat(7))
            make.height.equalTo(SizeFitFloat(19))
        }
        
        let moreBtn = LGTViewCreateUtil.share.createTextLGTButton(title: "更多", font: Font_Normal_12, color: GrayColor, selectedColor: GrayColor, dW: SizeFitFloat(12), dH: SizeFitFloat(5))
        self.addSubview(moreBtn)
        moreBtn.snp.makeConstraints { (make) in
            make.right.equalTo(-SizeFit(9))
            make.height.equalTo(SizeFitFloat(12))
            make.width.equalTo(SizeFitFloat(25))
            make.bottom.equalTo(recommendLabel)
        }

    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
